layui.define([ 'form', 'laydate', 'table','payOrderApi' ], function(exports) {
	var form = layui.form;
	var laydate = layui.laydate;
	var table = layui.table;
	var payOrderApi=layui.payOrderApi;
	var payOrderTable = null;
	
	var view ={
		
		init:function(){
			this.initTable();
			this.initSearchForm();
			this.initToolBar();
			window.dataReload = function(){
				Lib.doSearchForm($("#searchForm"),payOrderTable)
			}
			
			
		},
		initTable:function(){
			payOrderTable = table.render({
				elem : '#payOrderTable',
				height : Lib.getTableHeight(2),
				method : 'post',
				url : Common.ctxPath + '/admin/payorder/list.json' //数据接口
				,page : Lib.tablePage //开启分页
				,limit : 10,
				cols : [ [ //表头
				{
					type : 'checkbox',
					fixed:'left',
				}, {
					field : 'id',
					title : '订单号',
					width : 150,
					fixed:'left',
					sort : true
				}, {
					field : 'nickName',
					title : '用户昵称',
					width : 120
				}, {
					field : 'headimgurl',
					title : '用户头像地址',
					width : 150
				}, {
/*					field : 'tradeType',
					title : '交易类型',
					width : 120
				}, {*/
					field : 'type',
					title : '支付类型',
					width : 120
				}, {
					field : 'amount',
					title : '支付金额(元)',
					width : 120
				}, {
					field : 'requestTime',
					title : '支付时间',
					width : 120,
					templet:function(d){
						return Common.getDate(d.requestTime);
					},
					sort : true
				}, {
					field : 'orderStatus',
					title : '支付状态',
					width : 120,
					sort : true
				}

				] ]

			});
		},
		
		initSearchForm:function(){
			Lib.initSearchForm( $("#searchForm"),payOrderTable,form);
		},
		initToolBar:function(){
			toolbar = {
					edit : function() { //获取选中数目
						var data = Common.getOneFromTable(table,"payOrderTable");
						if(data==null){
							return ;
						}
						var url = "/admin/payorder/edit.do?id="+data.id;
						Common.openDlg(url,"订单管理>查看");
					},
					view : function() { //获取选中数目
						var data = Common.getOneFromTable(table,"payOrderTable");
						if(data==null){
							return ;
						}
						var url = "/admin/payorder/edit.do?id="+data.orderNo;
						Common.openDlg(url,"订单管理>查看");
					},
					del : function() { 
						layui.use(['del'], function(){
							  var delView = layui.del
							  delView.delBatch();
						});
					},
					exportPayOrder:function(){
					    Common.openConfirm("确认要导出这些订单信息?",function(){
					    	payOrderApi.exportPayOrder($("#searchForm"),function(fileId){
					           Lib.download(fileId);
					        })
		                })

                    }
				};
			$('.ext-toolbar').on('click', function() {
				var type = $(this).data('type');
				toolbar[type] ? toolbar[type].call(this) : '';
			});
		}
	}

	 exports('index',view);
	
});